﻿using Caliburn.PresentationFramework.ApplicationModel;
using Luna.Common;
using System.ComponentModel;
using Caliburn.PresentationFramework.Screens;
using XWord.Common;

namespace Luna.WPF.ApplicationFramework
{
    public interface IDetailPresenter<TEntity> : IScreen
    {
        TEntity Entity { get; set; }
    }

    public class DetailPresenter<TEntity> : ScreenConductor<IScreen>, IDetailPresenter<TEntity>
    {
        protected TEntity _entity;


        public DetailPresenter()
        {
          
        }

        protected override void OnInitialize()
        {
            IEditingObject editingObj = this.Entity as IEditingObject;
            editingObj.PropertyChanged += (s, e) => 
            {
                IEditing obj = (IEditing)s;
                if (obj.IsEnablePropertyChanged && e.PropertyName != "IsEditing" &&
                    e.PropertyName != "IsNew" && e.PropertyName != "IsEnablePropertyChanged")
                    obj.IsEditing = true;
            };
            base.OnInitialize();
        }

        public TEntity Entity
        {
            get { return _entity; }
            set
            {
                _entity = value;
                this.NotifyOfPropertyChange("Entity");
            }
        }
    }
}
